package com.jwthhealth_pub.old.constitution.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.jwthhealth_pub.old.common.Constant;
import com.jwthhealth_pub.old.constitution.ConstitutionTypeUtil;
import com.jwthhealth_pub.old.constitution.model.ConstitutionModel;
import com.jwthhealth_pub.old.constitution.view.adapter.ConstitutionAnswerAdatper;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/12/14.
 */

public class ConstitutionAnswerActivity extends Activity {
    @BindView(R.id.rv_answer)
    RecyclerView rvAnswer;
    @BindView(R.id.answer_topbar)
    TitleLayout answerTopbar;
    private int type;
    private ConstitutionAnswerAdatper adapter;
    private ConstitutionModel body;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_answer);
        ButterKnife.bind(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        Intent intent = getIntent();
        type = intent.getIntExtra(Constant.CONSTITUTION_TYPE, -1);
        Bundle bundle = intent.getExtras();
        body = (ConstitutionModel) bundle.getSerializable(Constant.CONSTITUTION_DATA);

        initClick();
        initRecyclerView();
    }

    private void initRecyclerView() {
        rvAnswer.setLayoutManager(new LinearLayoutManager(this));
        adapter = new ConstitutionAnswerAdatper(this, body.getData().getDesc(), body.getData().getResult(), type);
        rvAnswer.setAdapter(adapter);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        int width = adapter.getScoreSeekBar().getWidth();

        if (adapter.getScoreLayout().getChildCount() == 0) {
            adapter.putScorePos(width);
        }
    }

    private void initClick() {
        Log.d("ConstitutionAnswerActiv", "type:" + type);
        answerTopbar.setTitle(ConstitutionTypeUtil.getType(type) + getResources().getString(R.string.answer_request_title));

        answerTopbar.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }
}
